Skip to content

Launch-slot test: wait for a released slot a forked child may still hold - #52

Merged
agorischek merged 7 commits into
mainfrom
agorischek/launch-slot-flock
Nov 19, 2026
Merged

agorischek merged 7 commits into
mainfrom
agorischek/launch-slot-flock

Conversation

@agorischek

Copy link
Copy Markdown
Collaborator

Fixes the browser::tests::launches_wait_for_a_free_slot flake (cli/src/browser/tests.rs:56, "assertion failed: gate::acquire_in(…, Duration::ZERO).unwrap().held()"). It failed public-product (macos-latest) on #46 and #48.

Root cause

A launch slot is a flock on an open file description. Rust already opens the slot files O_CLOEXEC, but when another test thread forks while a slot is held, the child gets a copy of the descriptor. It keeps the lock until it execs. The test dropped its slots and immediately tried to take one with zero patience, so a fork in that window left both slots locked.

Fix

The fix is in the test, not the gate:

  • launches_wait_for_a_free_slot now reproduces the race deterministically. forking_child spawns true on another thread with a 300 ms pause in pre_exec, and the test releases the slots while that child holds their descriptors.
  • It then waits up to 10 s for a slot. With the old zero-patience assertion the test failed 3 of 3; with the fix it passes.

Production keeps flock:

  • A slot held a few milliseconds longer by a sibling's fork only delays one launch.
  • fcntl locks aren't inherited, but they don't exclude two threads of one process, and they drop on any close of the file.
  • macOS has no OFD locks.

Checks

  • cargo test -p projections-cli --lib browser::: 7/7, five runs
  • clippy -D warnings and the Windows-target cargo check --all-targets: clean
  • tools check --fast: clean

…es at once

launches_wait_for_a_free_slot dropped its two slots and took one with no
patience. A slot is a flock on an open file description: when another
test thread forks between the slot's open and its release, the child
holds a copy of the descriptor, and so the lock, until it execs (the
descriptor is O_CLOEXEC). The lock outlived the drop and the test failed.

The test now forks such a child itself (one pausing in pre_exec) while
it releases the slots, which made the old assertion fail every time, and
waits up to 10 s for the slot. Production keeps the flock: a slot held a
few milliseconds longer only delays one launch, fcntl locks wouldn't
exclude threads of one process, and macOS has no OFD locks.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The inherited-lock test can pass without exercising child-held descriptors because its pre-fork notification and fixed sleep do not reliably synchronize the parent and child.

1 open issue
What changed in this PR

Updates the CLI browser launch-slot test to tolerate locks briefly retained by forked children, addressing intermittent macOS CI failures without changing the production gate.

Changes:

  • Adds a Unix helper that delays child execution to exercise descriptor inheritance.
  • Allows up to 10 seconds for slot reacquisition and verifies both slots are held before testing cancellation.
File Description
packages/​cli/​src/​browser/​tests.rs Adds fork-delay coverage and bounded waits for released launch slots.

Review effort: Balanced

Comment thread packages/cli/src/browser/tests.rs Resolved
agorischek and others added 6 commits November 18, 2026 14:01
…ps the slots

From review: the child's 50 ms head start didn't establish that it held
the slot descriptors when the slots were dropped. ForkedChild now signals
from pre_exec through a pipe once forked and waits on a second pipe to
exec, so the test asserts the dropped slots stay locked while the child
holds them, then lets it exec and waits for a slot.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@agorischek
agorischek merged commit fa5b419 into main Nov 19, 2026
61 checks passed
@agorischek
agorischek deleted the agorischek/launch-slot-flock branch November 19, 2026 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants